'''
url = 'https://www.23us.so/files/article/html/13/13694/index.html'

regex_info = '<td class="L"><a href="(.*?)">(.*?)</a></td>'

regex_name = '<h1>(.*?)最新章节</h1>'

regex_author = '<h3>作者：(.*?)</h3>'


{
book_name:'xx',
book_author:'xx',
book_info:[(chapter_url,chapter_name),{chapter_url:'xxx',
                                       chapter_name:'xxx'},...]

        
}

'''
import re
import requests

class Spider:
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) \
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100\
Safari/537.36',
        }
    def __init__(self,
                 encode = 'utf-8',
                 url = 'https://www.23us.so/files/article/html/\
13/13694/index.html',
                 
                 **regexs,

                 ):
        self.encode = encode
        self.url = url
        self.regexs = regexs

    def get_info(self):

        r = requests.get(self.url,headers = self.headers)

        r.encoding = self.encode

        content = r.text
        
        #print(content)
        self.info_dict = {}

        for key,value in self.regexs.items():

            self.info_dict[key] = re.findall(value,content)

        return self.info_dict

if __name__ == '__main__':
    
    regex_info = '<td class="L"><a href="(.*?)">(.*?)</a></td>'

    regex_name = '<h1>(.*?)最新章节</h1>'

    regex_author = '<h3>作者：(.*?)</h3>'
    
    x = Spider(book_name = regex_name,
               book_author = regex_author,
               book_info = regex_info,
               )
    print(x.get_info())
        

























        
